#!/usr/bin/python
#coding=utf-8

import sys
import os
import json
import rados

import global_list

class CephClusterCommand(dict):
    """
    Issue a ceph command on the given cluster and provide the returned json
    """
    def __init__(self, cluster, **kwargs):
        dict.__init__(self)
        ret, buf, err = cluster.mon_command(json.dumps(kwargs), '', timeout=5)
        if ret != 0:
            self['err'] = err
        else:
            #self.update(json.loads(buf))
            self['result']=json.loads(buf)
    def __del__(self):
        pass

class CephClusterOsdCommand(dict):
    """
    Issue a ceph command on the given cluster and provide the returned json
    """
    def __init__(self, cluster, **kwargs):
        dict.__init__(self)
        ret, buf, err = cluster.osd_command(json.dumps(kwargs), '', timeout=5)
        if ret != 0:
            self['err'] = err
        else:
            self.update(json.loads(buf))
    def __del__(self):
        pass
